package com.dingwen.rabpro.config;

import com.dingwen.rabpro.constant.RabbitConstant;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * rabbitmq config direct
 *
 * @author dingwen
 * 2021.06.17 17:23
 */
//@Configuration
public class RabbitmqConfigurationDirect {

    /**
     * direct 交换机
     *
     * @return {@link DirectExchange}
     */
//    @Bean
    public DirectExchange directExchange() {
        // 交换机名称、持久态、关闭自动删除
        return ExchangeBuilder.directExchange(RabbitConstant.DIRECT_EXCHANGE_NAME)
                .durable(Boolean.TRUE)
                .autoDelete()
                .build();
    }

    /**
     * 短信队列
     *
     * @return {@link Queue}
     */
//    @Bean
    public Queue smsQueue() {
        return QueueBuilder.durable(RabbitConstant.DIRECT_QUEUE_SMS_NAME)
                .build();
    }


    /**
     * 邮件队列
     *
     * @return {@link Queue}
     */
//    @Bean
    public Queue emailQueue() {
        return QueueBuilder.durable(RabbitConstant.DIRECT_QUEUE_EMAIL_NAME)
                .build();
    }

    /**
     * 短信绑定
     *
     * @return {@link Binding}
     */
//    @Bean
    public Binding smsBinding() {
        return BindingBuilder.bind(smsQueue())
                .to(directExchange())
                .with(RabbitConstant.DIRECT_ROUTE_KEY_SMS);
    }


    /**
     * 邮箱绑定
     *
     * @return {@link Binding}
     */
//    @Bean
    public Binding emailBinding() {
        return BindingBuilder.bind(emailQueue())
                .to(directExchange())
                .with(RabbitConstant.DIRECT_ROUTE_KEY_EMAIL);
    }

}
